﻿@using System.Linq
@using Covenant.Core
@using Covenant.Models.Grunts
@model ReferenceSourceLibrary
@{
    Layout = "../GruntTask/_GruntTaskLayout";
    ViewData["Title"] = "GruntTasks";
    IEnumerable<ReferenceAssembly> ReferenceAssemblies = ViewBag.ReferenceAssemblies;
    IEnumerable<EmbeddedResource> EmbeddedResources = ViewBag.EmbeddedResources;
    IEnumerable<SelectListItem> assemblySelectList = ReferenceAssemblies.Select(RA =>
    {
        Console.WriteLine(Model.ReferenceAssemblies.Select(MRA => MRA.Id).Contains(RA.Id));
        return new SelectListItem { Text = RA.Name, Value = RA.Id.ToString(), Selected = Model.ReferenceAssemblies.Select(MRA => MRA.Id).Contains(RA.Id) };
    });
    IEnumerable<SelectListItem> resourceSelectList = EmbeddedResources.Select(ER =>
    {
        return new SelectListItem { Text = ER.Name, Value = ER.Id.ToString(), Selected = Model.EmbeddedResources.Select(MER => MER.Id).Contains(ER.Id) };
    });
}
<div class="d-flex justify-content-between flex-wrap flex-md-nowrap pb-2 mb-3">
    <h1 class="h2">Create ReferenceSourceLibrary</h1>
</div>

<form asp-action="Create">
    <div asp-validation-summary="All"></div>
    <input asp-for="Id" type="hidden">
    <div class="form-row">
        <div class="form-group col-md-4">
            <label asp-for="Name"></label>
            <input asp-for="Name" class="form-control">
        </div>
        <div class="form-group col-md-8">
            <label asp-for="Description"></label>
            <input asp-for="Description" class="form-control">
        </div>
    </div>
    <div class="form-row">
        <div class="form-group col-md-12">
            <label asp-for="Location"></label>
            <input asp-for="Location" class="form-control">
        </div>
    </div>
    <div class="form-row">
        <div class="form-group">
            <label asp-for="SupportedDotNetVersions"></label><br />
            <select asp-for="SupportedDotNetVersions" asp-items="@Html.GetEnumSelectList<Common.DotNetVersion>()" class="selectpicker show-menu-arrow" multiple data-dropup-auto="false" data-width="auto" data-live-search="true" data-selected-text-format="count > 3"></select>
        </div>
    </div>
    <div class="form-row">
        <div class="form-group">
            <label asp-for="ReferenceAssemblies"></label><br />
            <select asp-for="ReferenceAssemblies" class="selectpicker show-menu-arrow" multiple data-dropup-auto="false" data-width="auto" data-live-search="true" data-selected-text-format="count > 2">
                @foreach (var assembly in assemblySelectList)
                {
                    <option value="@assembly.Value">@assembly.Text</option>
                }
            </select>
        </div>
    </div>
    <div class="form-row">
        <div class="form-group">
            <label asp-for="EmbeddedResources"></label><br />
            <select asp-for="EmbeddedResources" class="selectpicker show-menu-arrow" multiple data-dropup-auto="false" data-width="auto" data-live-search="true" data-selected-text-format="count > 2">
                @foreach (var resource in resourceSelectList)
                {
                    <option value="@resource.Value">@resource.Text</option>
                }
            </select>
        </div>
    </div>

    <button type="submit" class="btn btn-primary"><span data-feather="plus"></span> Create</button>
</form>

@section Scripts {

}